package com.mq.rocketmq.springboot;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @Author: xiaoqiang
 * @Description:
 * @Date: 2024/7/7
 * @Version: 1.0
 */
@SpringBootTest
public class SyncSender {


    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Test
    public void syncSendMsg() throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer = rocketMQTemplate.getProducer();
        producer.setProducerGroup("msg-demo1");

        producer.setNamesrvAddr("localhost:9876");
        String topic = "topicDifListener";
        producer.start();
        Message message = new Message(topic, "hello world".getBytes());
        producer.send(message);

        producer.shutdown();
    }
}
